package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.AreaDivision;
import com.zygh.interactiveplatform.module.entity.AreaDivision;
import com.zygh.interactiveplatform.module.service.AreaDivisionService;
import com.zygh.interactiveplatform.module.service.AreaDivisionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-01-29
 */
@RestController
@RequestMapping("/area-division")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_AREADIVISION})
public class AreaDivisionController {
    @Resource
    private AreaDivisionService areaDivisionService;

    @ApiOperation(value = "区域新增", notes = "区域新增")
    @PostMapping("addAreaDivisione")
    @PcLog(logType = "2", module = SwaggerTagConst.Admin.MANAGER_AREADIVISION, content = "区域新增")
    public ResponseDTO addAreaDivisione(@RequestBody @Valid AreaDivision areaDivision) {
        return areaDivisionService.addAreaDivision(areaDivision);
    }
    @ApiOperation(value = "区域修改", notes = "区域修改")
    @PostMapping("updateAreaDivision")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_AREADIVISION, content = "区域修改")
    public ResponseDTO updateAreaDivision(@RequestBody @Valid AreaDivision areaDivision) {
        return areaDivisionService.updateAreaDivision(areaDivision);
    }
    @ApiOperation(value = "区域删除", notes = "区域删除")
    @PostMapping("deleteAreaDivision")
    @PcLog(logType = "4", module = SwaggerTagConst.Admin.MANAGER_AREADIVISION, content = "区域删除")
    public ResponseDTO deleteAreaDivision(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return areaDivisionService.deleteAreaDivision(new_id);
    }
    @ApiOperation(value = "查询所有区域", notes = "查询所有区域")
    @GetMapping("findAreaDivisionAll")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_AREADIVISION, content = "查询所有区域")
    public ResponseDTO findAreaDivisionAll(Integer current, Integer size) {
        return areaDivisionService.findAreaDivisionAll(current,size);
    }
}
